package com.yang.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

/*
手动获取实例对象，在多线程使用，因为多线程里面不允许自动注入
 */
@Service
public class ApplicationContextProvider implements ApplicationContextAware {
	private static ApplicationContext context;

	private ApplicationContextProvider() {
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		context = applicationContext;

	}

	public static <T> T getBean(String name, Class<T> aClass) {
		return context.getBean(name, aClass);
	}
}
